<<<<<<< .mine
var solved = false;
var len = 3;
var size = 100;
Playground.prototype = new Sprite();

function Configure(){
    this.configArray = new Array(len);
    for(var i = 0; i < len; i++){
        var array = new Array(len);  
        for (var j = 0; j < len; j++){
            array[j]=i+(j+2*i);
        }
        this.configArray[i]=array;
    } 
                
}
            
function Square(i,j,order,playground){   
    Sprite.apply(this);
    this.i = i;
    this.j = j;
    this.oznacene = false;
    this.order = order;
    this.border;
    this.picture;
    this.playGround = playground;
    this.init = init;
    const IMAGE_URL= Game.picturesPath +"levels/"+ "levelCircuit/obv"+ order +".png";
       
    this.setIJ = function(i,j){
        this.x = j*size;
        this.y = i*size;
        this.i = i;
        this.j = j;
    }
                
    this.setIJ(i,j);
    function init(){
        this.border = new Sprite();		
        this.border.graphics.beginFill(black);
        this.border.graphics.drawRect(- 2, - 2, size+4, size+4);
        this.border.visible = true;
        this.addChild(this.border);
        var bitmap = Game._game.bitmaps[IMAGE_URL];
        bitmap.x = 0;
        bitmap.y = 0;
        bitmap.alpha = 1;        
        this.buttonMode = true;
        this.mouseChildren=false;
        this.addChild(bitmap);                            
    }

    this.over = over;
    function over(e){
        e.target.alpha = 0.7;
    }
                
    this.out = out;
    function out(e){
        if ( e.target.oznacene ){
            e.target.alpha = 0.5;
        }
        else{
            e.target.alpha = 1;
        }
    }
                
    this.down = down;
    function down(e){
       
        if (e.target.oznacene){ 
            e.target.alpha = 1;
            e.target.oznacene = false;
            oznacenie = false;
            oznaceny = null;      
        }else if(!oznacenie){
            if (e.target.order != 4){
            e.target.alpha = 0.1; 
            e.target.oznacene = true;
            oznacenie = true;
            oznaceny = e.target;
            }
        }else{
            if (e.target.order == 4){      
                e.target.playGround.vymena(oznaceny.i,oznaceny.j, e.target.i, e.target.j);
            //solved = e.target.playGround.kontrola();
            //console.debug(solved);
            }else{
                oznaceny.alpha=1;
                oznaceny.oznacene=false;
                e.target.alpha = 0.1; 
                e.target.oznacene = true;
                oznaceny = e.target;
            }               
        }
        solved = e.target.playGround.kontrola();
        if(solved){
           e.target.parent.parent.levelSolved();
        }
    }
  
    this.addEventListener(MouseEvent.MOUSE_OVER, this.over);
    this.addEventListener(MouseEvent.MOUSE_OUT , this.out);
    this.addEventListener(MouseEvent.MOUSE_DOWN, this.down);
}
Square.prototype = new Sprite();
            
function Playground(x,y){
    this.playgroundArray = new Array(len);             
    Sprite.apply(this);
    this.debug = false;
    this.x = x;
    this.y = y;
    this.configure = new Configure();
    //this.buttonMode = true;
    //this.mouseChildren=false;
    this.init = init;
    //this.b;
    function init(){ 
        for(var i = 0; i < len; i++){
            var array = new Array(len);  
            for (var j = 0; j < len; j++){
                var square = new Square(i,j,i+(j+2*i),this);                                    
                array[j]= square;
                array[j].init();
                this.addChild(array[j]);
            }
            this.playgroundArray[i]=array;
        }
                  
    }
                
         
    this.vloz = vloz;
    function vloz(sq,i,j){  
        sq.setIJ(i, j);
        sq.oznacene = false;
        oznacenie=false;
        oznaceny= null;
        this.playgroundArray[i][j] = sq; 
    }

    this.susedne = susedne;
    function susedne(i1,j1, i2,j2){
        if ((i1>=0) && (i1< len) &&
            (i2>=0) && (i2< len) &&
            (j1>=0) && (j1< len) &&
            (j2>=0) && (j2< len) ){    
            if(((i1==i2-1)&&(j1==j2)) ||
                ((i1==i2+1)&&(j1==j2)) || 
                ((i1==i2)&&(j1==j2+1)) || 
                ((i1==i2)&&(j1==j2-1))   ){
                return true;
            }   
        }
        return false; 
    } 
                            
    this.vymena = vymena; 
    function vymena(i,j,volI,volJ){
        if (!this.debug){
        if (this.playgroundArray[volI][volJ].order == 4){
            var susedne = this.susedne(i,j,volI,volJ);
            if (susedne){ 
                var pom =  this.playgroundArray[i][j];
                this.vloz(this.playgroundArray[volI][volJ],i,j);
                this.vloz(pom,volI,volJ);
            }                      
        }
        }
        else{
                var pom =  this.playgroundArray[i][j];
                this.vloz(this.playgroundArray[volI][volJ],i,j);
                this.vloz(pom,volI,volJ);
        }
    }
                
    this.kontrola = kontrola;
    function kontrola(){
        for(var i = 0; i < len; i++){  
            for (var j = 0; j < len; j++){
                if(this.configure.configArray[i][j]!=this.playgroundArray[i][j].order) {       
                    return false;    
                } 
            }
        }
        this.parent.timer.TimerStop();
        return true;
        
    }
                
    this.miesanie = miesanie; 
    function miesanie(){
        var volY = 1;
        var volX = 1;
        for(var i = 0; i < 50; i++){  
           var rndY = volY;
           var rndX = volX;
           while (!this.susedne(rndY,rndX,volY,volX)){
                switch (volX){
                   case 0 : rndX = Math.floor(Math.random()*2);
                        break;
                   case 1 : rndX = Math.floor(Math.random()*3);
                        break;
                   case 2 : rndX = 1+Math.floor(Math.random()*2);
                        break;    
                }
                
                switch (volY){
                   case 0 : rndY = Math.floor(Math.random()*2);
                        break;
                   case 1 : rndY = Math.floor(Math.random()*3);
                        break;
                   case 2 : rndY = 1+Math.floor(Math.random()*2);
                        break;    
                }
           }
           this.vymena (rndX,rndY,volX,volY);
           volX=rndX;
           volY=rndY;
        }
                    
    } 
}=======
var solved = false;
var len = 3;
var size = 100;
function Configure(){
    this.configArray = new Array(len);
    for(var i = 0; i < len; i++){
        var array = new Array(len);  
        for (var j = 0; j < len; j++){
            array[j]=i+(j+2*i);
        }
        this.configArray[i]=array;
    } 
                
}
            
function Square(i,j,order,playground){   
    Sprite.apply(this);
    this.i = i;
    this.j = j;
    this.oznacene = false;
    this.order = order;
    this.border;
    this.picture;
    this.playGround = playground;
    this.init = init;
    const IMAGE_URL= "pictures/obv"+ order +".png";
       
    this.setIJ = function(i,j){
        this.x = j*size;
        this.y = i*size;
        this.i = i;
        this.j = j;
    }
                
    this.setIJ(i,j);
    function init(){
        this.border = new Sprite();		
        this.border.graphics.beginFill(black);
        this.border.graphics.drawRect(- 2, - 2, size+4, size+4);
        this.border.visible = true;
        this.addChild(this.border);
        var bitmapData = new BitmapData(IMAGE_URL);
        var bitmap = new Bitmap(bitmapData);
        bitmap.x = 0;
        bitmap.y = 0;
        bitmap.alpha = 1;        
        this.buttonMode = true;
        this.mouseChildren=false;
        this.addChild(bitmap);                            
    }

    this.over = over;
    function over(e){
        e.target.alpha = 0.7;
    }
                
    this.out = out;
    function out(e){
        if ( e.target.oznacene ){
            e.target.alpha = 0.5;
        }
        else{
            e.target.alpha = 1;
        }
    }
                
    this.down = down;
    function down(e){
       
        if (e.target.oznacene){ 
            e.target.alpha = 1;
            e.target.oznacene = false;
            oznacenie = false;
            oznaceny = null;      
        }else if(!oznacenie){
                      
            e.target.alpha = 0.1; 
            e.target.oznacene = true;
            oznacenie = true;
            oznaceny = e.target;
        }else{
            if (e.target.order == 4){      
                e.target.playGround.vymena(oznaceny.i,oznaceny.j, e.target.i, e.target.j);
            //solved = e.target.playGround.kontrola();
            //console.debug(solved);
            }else{
                oznaceny.alpha=1;
                oznaceny.oznacene=false;
                e.target.alpha = 0.1; 
                e.target.oznacene = true;
                oznaceny = e.target;
            }
                        
        }
        solved = e.target.playGround.kontrola();
        console.debug(e.target.parent.parent);
        if(solved){
           e.target.parent.parent.levelSolved();
        }
    }
  
    this.addEventListener(MouseEvent.MOUSE_OVER, this.over);
    this.addEventListener(MouseEvent.MOUSE_OUT , this.out);
    this.addEventListener(MouseEvent.MOUSE_DOWN, this.down);
}
Square.prototype = new Sprite();
            
function Playground(x,y){
    this.playgroundArray = new Array(len);             
    Sprite.apply(this);
    this.x = x;
    this.y = y;
    this.configure = new Configure();
    //this.buttonMode = true;
    //this.mouseChildren=false;
    this.init = init;
    //this.b;
    function init(){ 
        for(var i = 0; i < len; i++){
            var array = new Array(len);  
            for (var j = 0; j < len; j++){
                var square = new Square(i,j,i+(j+2*i),this);                                    
                array[j]= square;
                array[j].init();
                this.addChild(array[j]);
            }
            this.playgroundArray[i]=array;
        }
                  
    }
                
         
    this.vloz = vloz;
    function vloz(sq,i,j){  
        sq.setIJ(i, j);
        sq.oznacene = false;
        oznacenie=false;
        oznaceny= null;
        this.playgroundArray[i][j] = sq; 
    }

    this.susedne = susedne;
    function susedne(i1,j1, i2,j2){
        if ((i1>=0) && (i1< len) &&
            (i2>=0) && (i2< len) &&
            (j1>=0) && (j1< len) &&
            (j2>=0) && (j2< len) ){    
            if(((i1==i2-1)&&(j1==j2)) ||
                ((i1==i2+1)&&(j1==j2)) || 
                ((i1==i2)&&(j1==j2+1)) || 
                ((i1==i2)&&(j1==j2-1))   ){
                return true;
            }   
        }
        return false; 
    } 
                            
    this.vymena = vymena; 
    function vymena(i,j,volI,volJ){
        if (this.playgroundArray[volI][volJ].order == 4){
            var susedne = this.susedne(i,j,volI,volJ);
            if (susedne){ 
                var pom =  this.playgroundArray[i][j];
                this.vloz(this.playgroundArray[volI][volJ],i,j);
                this.vloz(pom,volI,volJ);
            }                      
        }         
    }
                
    this.kontrola = kontrola;
    function kontrola(){
        for(var i = 0; i < len; i++){  
            for (var j = 0; j < len; j++){
                //console.debug(this.configure.configArray[i][j]);
                if(this.configure.configArray[i][j]!=this.playgroundArray[i][j].order) {       
                    return false;    
                } 
            }
        }
        return true;
    }
                
    this.miesanie = miesanie; 
    function miesanie(){
        for(var i = 0; i < len; i++){  
            for (var j = 0; j < len; j++){
                var randomI = Math.floor((Math.random()*3));
                var randomJ = Math.floor((Math.random()*3));
                var pom =  this.playgroundArray[i][j];
                this.vloz(this.playgroundArray[randomI][randomJ],i,j);
                this.vloz(pom,randomI,randomJ);
            }
        }
                    
    } 
}
Playground.prototype = new Sprite();>>>>>>> .r36
